/*
 * @Author: your name
 * @Date: 2024-04-26 14:59:53
 * @LastEditTime: 2024-04-26 15:02:16
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\700.二叉搜索树中的搜索.cpp
 */
/*
 * @lc app=leetcode.cn id=700 lang=cpp
 *
 * [700] 二叉搜索树中的搜索
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    TreeNode* searchBST(TreeNode* root, int val) {
        // 递归停止条件
        if(root == nullptr || root->val == val){
            return root;
        }
        if(root->val < val) return searchBST(root->right, val);
        else{
            return searchBST(root->left, val);
        }
    }
};
// @lc code=end

